package com.lottery.ruok.lottrey.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.retrofitModule.response.GetRuleResponse;

import java.util.ArrayList;

/**
 * Created by ASUS on 2017/11/6.
 */

public class PlayRuleAdapter extends BaseAdapter {
    private int position;
    private Context mContext;
    private ArrayList<GetRuleResponse> getRuleResponses;

    public PlayRuleAdapter(int pos, Context context, ArrayList<GetRuleResponse> getRuleResponses) {
        position = pos;
        mContext = context;
        this.getRuleResponses = getRuleResponses;
    }

    @Override
    public int getCount() {
        if(getRuleResponses == null){
            return 0;
        }
        if(getRuleResponses.size() > position){
            return getRuleResponses.get(position).getChildren().size();
        } else {
            return 0;
        }
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            view = LayoutInflater.from(mContext).inflate(R.layout.play_rule_child_item, null);
            holder = new ViewHolder();
            holder.name = view.findViewById(R.id.name);
            holder.content = view.findViewById(R.id.content);

            view.setTag(holder);
        }

        holder.name.setText(getRuleResponses.get(position).getChildren().get(i).getName());
        holder.content.setText(getRuleResponses.get(position).getChildren().get(i).getHelp());

        return view;
    }

    static class ViewHolder {
        TextView name;
        TextView content;
    }
}
